#!/bin/bash
set -e
set -u
#
# Run a simple backup
#   then restore it.
#
TestName="$(basename "$(pwd)")"
export TestName

JobName=backup-susan-fd
. ./environment
. ${rscripts}/functions

${rscripts}/cleanup
${rscripts}/setup


# Directory to backup.
# This directory will be created by setup_data().
BackupDirectory="${tmp}/data"

# Use a tgz to setup data to be backed up.
# Data will be placed at "${tmp}/data/".
setup_data

start_test

cat <<END_OF_DATA >$tmp/bconcmds
@$out /dev/null
messages
@$out $tmp/log1.out
run job=$JobName yes
wait
messages
quit
END_OF_DATA

run_susan

@PHP@ -S 127.0.0.1:@php_port@ -t @SUSAN_WEBUI_PUBLIC_DIR@ >"$tmp/php.out" 2>&1 &

PHP_PID=$(echo $!)

# run tests

#
# test with admin profile resource
#
export SUSAN_WEBUI_PROFILE=@SUSAN_WEBUI_PROFILE@
export SUSAN_WEBUI_TESTNAME=@SUSAN_WEBUI_TESTNAME@
echo "test with ${SUSAN_WEBUI_PROFILE} profile:" >"$tmp/selenium.out" 2>&1
# WRONG: false | tee /tmp/tmp.txt has always $? == 0.
#@PYTHON@ @CMAKE_SOURCE_DIR@/webui/tests/selenium/webui-selenium-test.py -v "SeleniumTest.test_${SUSAN_WEBUI_TESTNAME}" | tee "$tmp/selenium.out" 2>&1
if ! @PYTHON@ @CMAKE_SOURCE_DIR@/webui/tests/selenium/webui-selenium-test.py -v "SeleniumTest.test_${SUSAN_WEBUI_TESTNAME}" >>"$tmp/selenium.out" 2>&1; then

    set_error "$(cat "$tmp/selenium.out")"

fi

kill "${PHP_PID}"

stop_susan

end_test
